
#include "cmd_stmflash.h"
#include "command.h"
#include <stdio.h>
#include "sys.h"
#include <string.h>
#include "stm_flash.h"


int do_stmflash ( int argc , char **argv )
{
	u32 flash_addr , ram_addr;
	u32 length;
	if ( argc != 5 )
	{
		goto ERR;
	}

	flash_addr = str2hex ( argv[2] );
	ram_addr = str2hex ( argv[3] );
	length = str2hex ( argv[4] );
	
	if ( flash_addr == 0xFFFFFFFF || ram_addr == 0xFFFFFFFF
		 || length == 0xFFFFFFFF )
	{
		goto ERR;
	}

	if ( 0 == strcmp ( "read" , argv[1] ) )
	{
		printf ( "Read Flash %08X to Ram %08X ... " , flash_addr , ram_addr );
		STMFLASH_Read ( flash_addr , (u32*)ram_addr , length );
	}
	else if ( 0 == strcmp ( "write" , argv[1] ) )
	{
		printf ( "Write Ram %08X to Flash %08X ... " , ram_addr , flash_addr );
		STMFLASH_Write ( flash_addr , (u32*)ram_addr , length );
	}
	printf ( "\r\n" );
	return 0; 
ERR:
	printf ( "Usage:	stmflash read/write flashaddr ramaddr length\r\n" );
	return -1;
}








